/**
 * Created by Administrator on 2017/5/14.
 */
let HOST = '//115.159.79.128:8002'
/*
window.location.hostname.indexOf('localhost') > -1 && (HOST = '127.0.0.1:8002')
window.location.hostname.indexOf('192.168.1.2') > -1 && (HOST = '192.168.1.2:8002')
window.location.hostname.indexOf('127.0.0.1') > -1 && (HOST = '127.0.0.1:8002')
console.log(window.location)*/
let ajax = (path, postData) => {
  let promiseXHR = new Promise((resolve, reject) => {
    let xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP")
    if (postData) {
      let body = JSON.stringify(postData)
      xhr.open(postData ? "POST" : "GET", HOST + path, true)
      xhr.setRequestHeader("Content-type", "application/json; charset=UTF-8")
      xhr.send(body)
    } else {
      xhr.open("GET", HOST + path, true)
      xhr.send(null)
    }
    xhr.onreadystatechange = function () {
      if (xhr.readyState == 4 && xhr.status >= 200 && xhr.status < 400) {
        resolve({'data': JSON.parse(xhr.responseText)})
      }
    }
  })
  return promiseXHR
}
